//
//  MTPaymentAPI.swift
//  MT
//
//  Created by ooops on 2020/3/17.
//  Copyright © 2020 张强. All rights reserved.
//

import Foundation

/// 网络
import Moya
import DeviceKit
import SwiftyRSA
import Security

import Result

enum MTPaymentAPI {
    /// 充值的商品列表
    case list
    /// 创建微信支付订单信息
    case weChatPay(id: Int)
    /// 苹果充值商品列表
    case appleList
    /// 苹果内购支付
    case iosPay(payload: String)
    
}


// MARK: ------------------ Api 参数 ----------------------
extension MTPaymentAPI: MTTargetType {

    /// 请求头
    public var headers: [String : String]? {
        guard let accessToken = UserDefaults.MTUserCenter.token.storedString else { return nil }
        return ["Access-Token": accessToken]
    }
    
    /// 基路径
    public var baseURL: URL {
        return URL(string: AuthServerBaseUrl)!
    }
    
    /// 路径
    public var path: String {
        switch self {
        case .list:
            return "/invest/list"
        case .weChatPay(_):
            return "/pay/wechat/app/prepare"
        case .appleList:
            return "/pay/list-apple-pay"
        case .iosPay(_):
            return "/pay/iospay"
        }
    }
    
    /// 请求方法
    public var method: Moya.Method {
        return .post
    }
    
    /// 参数
    var params: [String: Any]? {
        
        switch self {
        case .list, .appleList:
            return nil
        case let .weChatPay(id):
            return ["id" : id]
        case let .iosPay(payload):
            return ["payload" : payload]
        }
        
    }
    
}


